(function(){"use strict";BX.namespace("BX.Landing.UI.Field");var t=BX.Landing.Utils.trim;var e=BX.Landing.Utils.clone;var i=BX.Landing.Utils.isPlainObject;var n=BX.Landing.Utils.decodeDataValue;var a=BX.Landing.Utils.fireCustomEvent;var s=BX.Landing.Utils.htmlToElement;var d=BX.Landing.Utils.style;var l=BX.Landing.Utils.escapeText;BX.Landing.UI.Field.Link=function(n){BX.Landing.UI.Field.BaseField.apply(this,arguments);this.options=n.options||{};BX.remove(this.input);this.onValueChangeHandler=n.onValueChange?n.onValueChange:function(){};this.content=i(this.content)?this.content:{};this.content=e(this.content);this.content.text=t(this.content.text);this.content.href=t(l(this.content.href));this.content.target=t(l(this.content.target));this.skipContent=n.skipContent;this.customUrlDisabled=n.disableCustomURL;this.detailPageMode=n.detailPageMode===true;if(!this.containsImage()&&!this.containsHtml()){if(BX.Type.isStringFilled(this.content.text)){this.content.text=this.content.text.replace("&nbsp;"," ")}this.content.text=l(this.content.text)}this.input=new BX.Landing.UI.Field.Text({placeholder:BX.Landing.Loc.getMessage("FIELD_LINK_TEXT_LABEL"),selector:this.selector,content:BX.Text.decode(this.content.text),textOnly:true,onValueChange:function(){this.onValueChangeHandler(this);var t=this.hrefInput.getValue();if(t==="#landing0"){var e=this.input.getValue();var i=this.hrefInput.input.firstElementChild;if(i){var n=i.querySelector(".landing-ui-field-url-placeholder-text");n.innerText=BX.Text.decode(e.replace(/&nbsp;/g," "))}}var a=new BX.Event.BaseEvent({data:{value:this.getValue()},compatData:[this.getValue()]});this.emit("change",a)}.bind(this)});if(this.skipContent){this.input.layout.hidden=true;this.header.hidden=true}this.hrefInput=new BX.Landing.UI.Field.LinkURL({title:BX.Landing.Loc.getMessage("FIELD_LINK_HREF_LABEL"),placeholder:BX.Landing.Loc.getMessage("FIELD_LINK_HREF_PLACEHOLDER"),selector:this.selector,content:this.content.href,contentRoot:this.contentRoot,onInput:this.onHrefInput.bind(this),textOnly:true,options:this.options,disallowType:n.disallowType,disableBlocks:n.disableBlocks,disableCustomURL:n.disableCustomURL,allowedTypes:n.allowedTypes,detailPageMode:n.detailPageMode===true,sourceField:n.sourceField,onValueChange:function(){this.onValueChangeHandler(this);this.onHrefValueChange();var t=new BX.Event.BaseEvent({data:{value:this.getValue()},compatData:[this.getValue()]});this.emit("change",t)}.bind(this),onNewPage:function(){var t=this.input.getValue();var e=this.hrefInput.input.firstElementChild;if(e){var i=e.querySelector(".landing-ui-field-url-placeholder-text");i.innerHTML=t.replace(/&nbsp;/g," ")}}.bind(this)});this.targetInput=new BX.Landing.UI.Field.DropdownInline({title:BX.Landing.Loc.getMessage("FIELD_LINK_TARGET_LABEL"),selector:this.selector,className:"landing-ui-field-dropdown-inline",content:this.content.target,contentRoot:this.contentRoot,items:{_self:BX.Landing.Loc.getMessage("FIELD_LINK_TARGET_SELF"),_blank:BX.Landing.Loc.getMessage("FIELD_LINK_TARGET_BLANK"),_popup:BX.Landing.Loc.getMessage("FIELD_LINK_TARGET_POPUP")},onValueChange:function(){this.onValueChangeHandler(this);var t=new BX.Event.BaseEvent({data:{value:this.getValue()},compatData:[this.getValue()]});this.emit("change",t)}.bind(this)});this.mediaButton=new BX.Landing.UI.Button.BaseButton(this.selector+"_media",{html:'<span class="fa fa-bolt"></span>&nbsp;'+BX.Landing.Loc.getMessage("LANDING_CONTENT_URL_MEDIA_BUTTON"),className:"landing-ui-field-link-media",onClick:this.onMediaClick.bind(this),disabled:true});this.mediaLayout=BX.create("div",{props:{className:"landing-ui-field-link-media-layout"}});this.mediaHelpButton=new BX.Landing.UI.Button.BaseButton(this.selector+"_media_qa",{html:'<span class="fa fa-question-circle"></span>&nbsp;',className:"landing-ui-field-link-media-help"});this.mediaHelpButton.layout.addEventListener("mouseover",this.onMediaHelpButtonMouseover.bind(this));this.mediaHelpButton.layout.addEventListener("mouseout",this.onMediaHelpButtonMouseout.bind(this));if(this.containsImage()||this.containsHtml()){this.input.layout.hidden=true;this.header.hidden=true;this.hrefInput.header.innerHTML=this.header.innerHTML}this.wrapper=BX.Landing.UI.Field.Link.createWrapper();this.left=BX.Landing.UI.Field.Link.createLeft();this.center=BX.Landing.UI.Field.Link.createCenter();this.right=BX.Landing.UI.Field.Link.createRight();this.left.appendChild(this.input.layout);this.center.appendChild(this.hrefInput.layout);this.right.appendChild(this.targetInput.layout);this.right.appendChild(this.mediaButton.layout);this.right.appendChild(this.mediaHelpButton.layout);this.wrapper.appendChild(this.left);this.wrapper.appendChild(this.center);this.wrapper.appendChild(this.right);this.layout.appendChild(this.wrapper);this.layout.appendChild(this.mediaLayout);this.layout.classList.add("landing-ui-field-link");if(!this.customUrlDisabled){this.adjustVideo()}if(this.content.target==="_popup"){this.adjustVideo()}this.adjustEditLink();this.adjustTarget()};BX.Landing.UI.Field.Link.createWrapper=function(){return BX.create("div",{props:{className:"landing-ui-field-link-wrapper"}})};BX.Landing.UI.Field.Link.createCenter=function(){return BX.create("div",{props:{className:"landing-ui-field-link-center"}})};BX.Landing.UI.Field.Link.createLeft=function(){return BX.create("div",{props:{className:"landing-ui-field-link-left"}})};BX.Landing.UI.Field.Link.createRight=function(){return BX.create("div",{props:{className:"landing-ui-field-link-right"}})};BX.Landing.UI.Field.Link.prototype={constructor:BX.Landing.UI.Field.Link,__proto__:BX.Landing.UI.Field.BaseField.prototype,superClass:BX.Landing.UI.Field.BaseField,onHrefValueChange:function(){},adjustEditLink:function(){var t=this.hrefInput.getPlaceholderType();var e=BX.Landing.Env.getInstance().getType();if(t==="PAGE"&&e!=="KNOWLEDGE"&&e!=="GROUP"){var i=this.hrefInput.getValue();if(BX.type.isString(i)&&i.length>0){this.hrefInput.getPageData(i).then(function(t){var e=BX.Landing.Main.getInstance().options.params.sef_url.landing_view;var i=e.replace("#site_show#",t.siteId).replace("#landing_edit#",t.id);[].slice.call(this.layout.querySelectorAll(".landing-ui-field-edit-link")).forEach(BX.remove);this.editLink=this.createEditLink(BX.Landing.Loc.getMessage("LANDING_LINK_FILED__EDIT_PAGE_LINK_LABEL"),i);this.layout.appendChild(this.editLink)}.bind(this))}}},createEditLink:function(t,e){return BX.create("div",{props:{className:"landing-ui-field-edit-link"},children:[BX.create("a",{attrs:{href:e,target:"_blank",title:BX.Landing.Loc.getMessage("LANDING_LINK_FILED__EDIT_LINK_TITLE")},text:t})]})},isChanged:function(){return JSON.stringify(this.content)!==JSON.stringify(this.getValue())},containsImage:function(){return!!BX.create("div",{html:this.content.text}).querySelector("img")},containsHtml:function(){var t=s(this.content.text);return!!t&&!t.matches("br")},getValue:function(){var e=this.input.getValue().replace(/&nbsp;/g," ");var a={text:n(t(e)),href:t(this.hrefInput.getValue()),target:t(this.targetInput.getValue())};if(this.isAvailableMedia()&&this.isEnabledMedia()&&this.mediaService){a.attrs={"data-url":t(this.mediaService.getEmbedURL())}}if(this.hrefInput.getDynamic()){if(!i(a.attrs)){a.attrs={}}if(this.hrefInput.input.firstElementChild){a.attrs["data-url"]=this.hrefInput.input.firstElementChild.getAttribute("data-url")}a.attrs["data-dynamic"]=this.hrefInput.getDynamic()}if(this.skipContent){delete a["text"]}return a},setValue:function(t){if(i(t)){this.input.setValue(l(t.text));this.hrefInput.setValue(t.href);this.targetInput.setValue(l(t.target))}this.adjustEditLink();this.adjustTarget()},adjustTarget:function(){if(!this.isAvailableMedia()){var t=BX.Landing.Env.getInstance().getType();var e=this.getValue();this.targetInput.enable();if(t==="KNOWLEDGE"||t==="GROUP"){this.targetInput.disable();if(/^#diskFile([0-9]+)$/.test(e.href)){this.targetInput.setValue("_blank")}else if(/^#(\w+)([0-9])$/.test(e.href)){this.targetInput.setValue("_self")}else{this.targetInput.setValue("_blank")}}else{if(e.href.startsWith("#crmFormPopup")){this.targetInput.disable()}if(e.href.startsWith("#crmPhone")){this.targetInput.disable()}}}},reset:function(){this.setValue({text:"",href:"",target:"_self"})},enableMedia:function(){this.mediaButton.enable();this.targetInput.disable();this.targetInput.closePopup();this.targetInput.setValue("_popup");this.readyToSave=true;if(!this.mediaService.isDataLoaded){this.readyToSave=false;BX.addCustomEvent(this.mediaService,"onDataLoaded",(()=>{this.readyToSave=true;this.emit("onChangeReadyToSave")}))}this.emit("onChangeReadyToSave");this.showMediaPreview()},disableMedia:function(){if(this.isEnabledMedia()){this.mediaButton.disable();this.targetInput.enable();this.targetInput.closePopup();this.targetInput.setValue("_self");if(!this.readyToSave){this.readyToSave=true;this.emit("onChangeReadyToSave")}this.hideMediaPreview();this.hideMediaSettings()}},isEnabledMedia:function(){return this.mediaButton.isEnabled()},showMediaSettings:function(){if(this.isAvailableMedia()){this.hideMediaSettings();this.mediaSettings=this.mediaService.getSettingsForm();if(this.mediaSettings){this.mediaLayout.appendChild(this.mediaSettings.layout)}}},hideMediaSettings:function(){if(this.mediaSettings){BX.remove(this.mediaSettings.layout)}},isAvailableMedia:function(){const t=new BX.Landing.MediaService.Factory;return!!t.getRelevantClass(this.hrefInput.getValue())},onMediaClick:function(){if(this.isAvailableMedia()){if(!this.isEnabledMedia()){if(!this.mediaService){this.adjustVideo()}else{this.enableMedia()}}else{this.disableMedia()}}},onMediaHelpButtonMouseover:function(t){BX.Landing.UI.Tool.Suggest.getInstance().show(this.mediaHelpButton.layout,{description:BX.create("div",{props:{className:"landing-ui-field-link-media-help-popup-content"},children:[BX.create("div",{props:{className:"landing-ui-field-link-media-help-popup-content-title"},html:BX.Landing.Loc.getMessage("LANDING_CONTENT_URL_MEDIA_HELP_TITLE")}),BX.create("div",{props:{className:"landing-ui-field-link-media-help-popup-content-content"},html:BX.Landing.Loc.getMessage("LANDING_CONTENT_URL_MEDIA_HELP_2")})]}).outerHTML,angleOffset:53})},onMediaHelpButtonMouseout:function(){BX.Landing.UI.Tool.Suggest.getInstance().hide()},showMediaPreview:function(){var t=new BX.Loader({target:this.mediaLayout,mode:"inline",offset:{top:"calc(50% - 55px)",left:"calc(50% - 55px)"}});this.video=t.layout;t.show();return this.mediaService.getURLPreviewElement().then(function(t){BX.remove(this.video);this.video=t;this.mediaLayout.appendChild(this.video);this.showMediaSettings()}.bind(this),function(){this.hideMediaSettings();BX.remove(this.video)}.bind(this))},hideMediaPreview:function(){if(this.video){BX.remove(this.video)}},adjustVideo:function(){var t=BX.Landing.Env.getInstance().getType();if(t!=="KNOWLEDGE"&&t!=="GROUP"){var e="attrs"in this.content&&"data-url"in this.content.attrs?this.content.attrs["data-url"]:"";var i=new BX.Landing.MediaService.Factory;this.mediaService=i.create(this.hrefInput.getValue(),BX.Landing.Utils.getQueryParams(e));if(this.mediaService){this.disableMedia();if(this.isAvailableMedia()){this.enableMedia()}}else{this.disableMedia()}}},onHrefInput:function(){if(!this.customUrlDisabled){this.adjustVideo()}this.adjustEditLink();this.adjustTarget()}}})();
//# sourceMappingURL=link_field.map.js